package com.cq.hd.app.controller;

import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.Throw;
import com.cq.hd.product.api.TbActiveCollectApi;
import com.cq.hd.product.api.dto.ActiveCollectPageDto;
import com.cq.hd.product.api.dto.ActiveCollectUpdateDto;
import com.cq.hd.product.api.vo.ActiveCollectPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/activeCollect")
@Api(tags = "活动收藏相关接口")
public class ActiveCollectController {

    @Autowired
    private TbActiveCollectApi activeCollectApi;

    @ApiOperation(value = "活动收藏/取消收藏")
    @ApiImplicitParam(name = "activeCollectUpdateDto", value = "实体", paramType = "body", dataType = "ActiveCollectUpdateDto")
    @PutMapping("/updateState")
    public Result<Object> updateState(@RequestBody ActiveCollectUpdateDto activeCollectUpdateDto, @ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        if (activeCollectUpdateDto.getActiveId() == null || activeCollectUpdateDto.getActiveId() <= 0) {
            Throw.isBusinessException("活动id不能为空");
        }

        activeCollectUpdateDto.setUserId(appLoginUser.getUserId());
        return activeCollectApi.updateState(activeCollectUpdateDto);
    }

    @ApiOperation(value = "收藏活动列表")
    @ApiImplicitParam(name = "activeCollectPageDto", value = "实体", paramType = "query", dataType = "ActiveCollectPageDto")
    @ApiResponse(response = ActiveCollectPageVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/page")
    public Result<Page<ActiveCollectPageVo>> page(@ApiIgnore @LoginUser AppLoginUser appLoginUser, ActiveCollectPageDto activeCollectPageDto) {
        activeCollectPageDto.setUserId(appLoginUser.getUserId());
        return activeCollectApi.page(activeCollectPageDto);
    }

}
